package com.share.example.selenium.schedule;


import com.share.example.selenium.enums.BusinessEnum;
import com.share.example.selenium.model.db.User;
import com.share.example.selenium.service.IUserService;
import com.share.example.selenium.service.hzhc.hm.HcxxHmLoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Slf4j
@Component
public class hzhc_task_v2_schedule {
    @Autowired
    private IUserService userService;
    @Autowired
    private HcxxHmLoginService hmLoginService;


    //0 0/20 7-10 * * ? 每天7点到10点之间每隔20分钟执行一次
    @Scheduled(cron = "0 0/30 20-22 * * ?")
    public void initHttp() {
        Date date = new Date();
        String bizCode = BusinessEnum.HZHC_TASK_V2.code;

        List<User> userList = userService.listByBizCode(bizCode);
        if (userList == null) {
            return;
        }

        for (User user : userList) {
            try {
                //1.调用查询接口保持token
//                String msg = refreshOneUserInfo(user);

                //2.登录获取token
                hmLoginService.fixLoginform(user.getUserName(), user.getPassWord());
            } catch (Exception e) {
                log.error("刷新异常", e);
            }
        }
    }
}
